package com.gitee.feizns.convert.method;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author feizns
 * @since 2019/5/28
 */
public class MethodSelectionStrategyList {

    /**
     * 方法选择策略列表
     */
    private List<MethodSelectionStrategy> selectionStrategiesList;

    public MethodSelectionStrategyList(MethodSelectionStrategy... strategy) {
        this.selectionStrategiesList = new ArrayList<>(Arrays.asList(strategy));
    }

    public MethodWrapper find(Class<?> targetType, Object original, Method... methods) {
        for (MethodSelectionStrategy strategy : selectionStrategiesList) {
            MethodWrapper methodWrapper = strategy.find(targetType, original, methods);
            if ( methodWrapper != null )
                return methodWrapper;
        }
        return null;
    }

    /**
     * 添加方法选择策略
     * @param strategy
     */
    public void addMethodSelectionStrategy(MethodSelectionStrategy strategy) {
        selectionStrategiesList.add(strategy);
    }

}
